<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<script>
			window.onload = function() {
				/**
				 * 第一题
				 * @param func
				 * @param times
				 * @param wait
				 * @returns {repeatImpl}
				 */
				function repeat(func, times, wait) {
					//不用匿名函数是为了方便调试
					function repeatImpl() {
						var handle,
							_arguments = arguments,
							i = 0;
						handle = setInterval(function() {
							i = i + 1;
							//到达指定次数取消定时器
							if (i === times) {
								clearInterval(handle);
								return;
							}
							func.apply(null, _arguments);
						}, wait);
					}
					return repeatImpl;
				}
				//测试用例
				var repeatFun = repeat(alert, 4, 3000);
				repeatFun("hellworld");
			}
		</script>
	</body>

</html>